package com.asset.dispoal.verdict.service.common;

import com.asset.dispoal.verdict.domain.db.entity.GbJudgmentBookItem;
import com.asset.dispoal.verdict.domain.db.mapper.GbJudgmentBookItemMapper;
import com.asset.dispoal.verdict.dto.mode.ExtractParam;
import com.asset.dispoal.verdict.dto.mode.JudgmentItem;
import com.asset.dispoal.verdict.service.converter.GbJudgmentBookConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.Arrays;
import java.util.List;

/**
 * @description: 正则列表使用@符合分割
 * @author: yf
 * @date: 2022-12-01 13:49:15
 */
@Repository
public class GetExtractParamCommand implements BaseCommand<String, Result> {
    @Autowired
    private GbJudgmentBookItemMapper judgmentBookItemMapper;

    @Override
    public Result execute(String bookId) {
        List<GbJudgmentBookItem> gbJudgmentBookItems = judgmentBookItemMapper.getBookItemByBookId(bookId);
        List<JudgmentItem> judgmentItems = GbJudgmentBookConverter.INSTANCE.gbToRes(gbJudgmentBookItems);
        judgmentItems.forEach(judgmentItem -> judgmentItem.getJudgmentBookItemDetailList().forEach(judgmentDetail -> {
            String[] split = judgmentDetail.getExpression().split("@@");
            judgmentDetail.setExpressions(Arrays.asList(split));
        }));

        ExtractParam extractParam = new ExtractParam(judgmentItems);
        return Result.ok(extractParam);
    }
}
